package com.meilai.project.controller.web.system;


import com.alibaba.fastjson.JSONObject;
import com.meilai.project.dto.CommonResult;
import com.meilai.project.dto.system.MessageCenterSearchDTO;
import com.meilai.project.service.system.MessageCenterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 张驰
 * @since 2022-04-15
 */
@Api(value = "Web端消息中心控制器", description = "Web端消息中心相关")
@RestController
@RequestMapping("api/web/message")
public class WebMessageCenterController {

    @Autowired
    private MessageCenterService service;

    @GetMapping("list")
    @ApiOperation(value = "列表")
    public CommonResult list(@RequestParam(name = "page", defaultValue = "1") Integer page,
                             @RequestParam(name = "page_size", defaultValue = "10") Integer page_size,
                             @RequestParam(value = "type", required = false) Integer type) {
        MessageCenterSearchDTO search = new MessageCenterSearchDTO();
        search.setType(type);
        return new CommonResult().success(service.selectPageList(page, page_size, search));
    }

    @PostMapping("set_has_read")
    @ApiOperation(value = "设置已读")
    public CommonResult alinePointNumById(@RequestBody JSONObject dto) {
        return new CommonResult().success(service.setHasReadByIds(dto.getJSONArray("ids").toJavaList(Long.class)));
    }

    @GetMapping("get_own_unread_count")
    @ApiOperation(value = "获取未读消息个数")
    public CommonResult getOwnUnReadCOunt() {
        return new CommonResult().success(service.getOwnUnReadCount());
    }
}
